package com.jszc.lottery.common.datatest;

import com.jszc.lottery.common.datatest.lambda.LambdaUtil;

import java.util.List;

public class BaseDataListResp extends BaseResponse {

    public BaseDataListResp() {
    }

    /**
     * data list
     */
    private CommuDic[] entities = null;

    public CommuDic[] getEntities() {
        if (this.entities == null) {
            return new CommuDic[]{};
        }
        return this.entities;
    }

    public void setEntities(CommuDic[] entities) {
        this.entities = entities;
    }

    public void setEntityList(List<CommuDic> entityList){
        this.entities = LambdaUtil.listToArray(CommuDic.class,entityList);
    }

    /**
     * the total num of data list when paging
     */
    private long totalCount;

    public long getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(long totalCount) {
        this.totalCount = totalCount;
    }

    /**
     * 是否自动计算页总数
     */
    private boolean autoCalcTotalCount;

    public boolean isAutoCalcTotalCount() {
        return autoCalcTotalCount;
    }

    public void setAutoCalcTotalCount(boolean autoCalcTotalCount) {
        this.autoCalcTotalCount = autoCalcTotalCount;
    }

    /**
     * 分页虚拟增量
     */
    public final int pageVirtualIncrement = 5;
    /**
     * 自动计算页总数
     */
    public void isAutoCalcTotalCount(int pageSize, int pageIndex, int curPageRecordSize) {
        this.totalCount = pageSize * pageIndex;
        if (curPageRecordSize >= pageSize) {
            this.totalCount += pageVirtualIncrement;
        } else {
            this.totalCount = this.totalCount - (pageSize - curPageRecordSize);
        }
        this.autoCalcTotalCount = true;
    }
}